﻿using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using Flexible.Implementions.Bases;
using Flexible.Interfaces;

namespace Flexible.Wpf
{
    public class MenuPlugin : PluginBase
    {
        public MenuPlugin()
        {
            exit = new MenuItem();
            exit.Header = "E_xit";
            exit.Click += (sender, e) => Application.Current.Shutdown();

            file = new MenuItem();
            file.Header = "_File";
            file.Items.Add(exit);

            menu = new Menu();
            menu.Items.Add(file);
        }

        readonly Menu menu;
        readonly MenuItem file;
        readonly MenuItem exit;

        public Menu Menu
        {
            get { return menu; }
        }

        public MenuItem File
        {
            get { return file; }
        }

        public MenuItem Exit
        {
            get { return exit; }
        }

        public override void Enable(IPluginActivateContext context)
        {
            WindowPlugin win = context.GetRequirement("Flexible.Wpf.Window") as WindowPlugin;
            win.MainRegion.Children.Add(menu);
        }

        public override void Disable(IPluginActivateContext context)
        {
            WindowPlugin win = context.GetRequirement("Flexible.Wpf.Window") as WindowPlugin;
            win.MainRegion.Children.Remove(menu);
        }

        public override IEnumerable<IPluginQuery> Requirements
        {
            get
            {
                yield return new PluginQuery("Flexible.Wpf.Window", new Version(1, 0, 0, 0));
            }
        }

        #region Info
        public override string Name
        {
            get { return "Menu"; }
        }

        public override string Description
        {
            get { return "Main Menu"; }
        }

        public override string Author
        {
            get { return "deerchao"; }
        }

        public override DateTime ReleaseTime
        {
            get { return new DateTime(2008, 4, 9); }
        }

        public override string Id
        {
            get { return "Flexible.Wpf.Menu"; }
        }

        public override Version Version
        {
            get { return new Version(1, 0, 0, 0); }
        }

        public override Version CompatibleVersion
        {
            get { return new Version(1, 0, 0, 0); }
        }
        #endregion
    }
}
